#include "buffer.h"

s_buffer* createBuffer( s_uint size ) {
	s_buffer* buff;
	
	buff = (s_buffer*)malloc( sizeof( s_buffer ) );
	buff->data = (s_ubyte*)calloc( size, sizeof( s_ubyte ) );
	buff->size = size;
	
	memset( buff->data, 0x65, size );
	return buff;
}

void destroyBuffer( s_buffer* buff ) {
	free( buff->data );
	free( buff );
}

void append( s_buffer* buff, s_ubyte* data, s_uint size ) {
	s_uint total = buff->size + size;
	s_ubyte* d = (s_ubyte*)calloc( total, sizeof( s_ubyte ) );
	
	memcpy( d, buff->data, buff->size );
	memcpy( &d[ buff->size ], data, size );
	free( buff->data );
	
	buff->data = d;
	buff->size = total;
}

void setBuffer( s_buffer* buff, s_ubyte* data, s_uint size ) {
	memcpy( buff->data, data, size );
}
